package handler

import (
	"Gin/api/request"
	"Gin/global/model"
	context2 "context"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"net/http"
	"serve/videoSrv"
)

func VideoGet(context *gin.Context) {
	var VideoGetRequest request.VideoGetRequest
	if err := context.ShouldBind(&VideoGetRequest); err != nil {
		context.JSON(http.StatusBadRequest, gin.H{
			"code":    http.StatusBadRequest,
			"message": err.Error(),
		})
		return
	}
	context.Request.ParseForm()
	user_id_jaon := context.Request.Form.Get("UserId")
	var UserId int64
	json.Unmarshal([]byte(user_id_jaon), &UserId)
	show, err := model.VideoClient.VideoShow(context2.Background(), &videoSrv.VideoShowRequest{
		Vid: int64(VideoGetRequest.Vid),
		Uid: UserId,
	})
	if err != nil {
		context.JSON(http.StatusBadRequest, gin.H{
			"code":    http.StatusBadRequest,
			"message": err.Error(),
		})
		return
	}
	context.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "获取成功",
		"data":    show,
	})
}
